import Vue from 'vue'
import VueRouter from 'vue-router'
// 外网路由懒加载
const Index = () => import('../views/page/Index')
const AboutUs = () => import('../views/page/aboutUs/AboutUs')
const Competition = () => import('views/page/competition/Competition')
const JionUs = () => import('views/page/joinUs/JoinUs')
const Plan = () => import('../views/page/plan/Plan')
const Story = () => import('views/page/story/Story')
const Login = () => import('../views/page/login/Login')
// 内网路由懒加载及导入
const Card = () => import('../views/pageIn/home/components/Card')
const Home = () => import('views/pageIn/home/Home')
const Statement = () => import('views/pageIn/statement/Statement')
const Group = () => import('../views/pageIn/group/Group')
const Mine = () => import('../views/pageIn/mine/Mine')
const CreateClock = () => import('../views/pageIn/clock/CreateClock')
const Publish = () => import('../views/pageIn/clock//components/Publish')
const PublishDetail = () => import('../views/pageIn/clock//components/PublishDetail')
const CreatePublish = () => import('../views/pageIn/clock//components/CreatePublish')
const CreateMessage = () => import('../views/pageIn/clock//components/CreateMessage')

const CreateGroup = () => import('../views/pageIn/group/childComps/CreateGroup')
const GroupShow = () => import('../views/pageIn/group/childComps/GroupShow')

// 内网消息中心路由懒加载及导入
const Message = () => import('../views/pageIn/message/Message')
const Sign = () => import('../views/pageIn/message/components/Sign/Sign')
const Notice = () => import('../views/pageIn/message/components/Notice/Notice')
const OtherMessage = () => import('../views/pageIn/message/components/OtherMess/OtherMess')
// 内网小组路由懒加载及导入
const GroupDetail = () => import('../views/pageIn/group/childComps/GroupDetail')
const Book = () => import('../views/pageIn/memory/components/Book')
const Plans = () => import('../views/pageIn/memory/components/Plans')
const Time = () => import('../views/pageIn/memory/components/Time')
const Wirte = () => import('../views/pageIn/memory/components/Wirte')
const CreateBook = () => import('../views/pageIn/memory/components/CreateBook')
const writeArticle = () => import('../views/pageIn/group/childComps/writeArticle')
const GroupSetting = () => import('../views/pageIn/group/childComps/GroupSetting')
const ArticleShow = () => import('../views/pageIn/group/childComps/ArticleShow')

// 关于我们路由
const StateMent = () => import("../views/pageIn/statement/Statement.vue")
const ProductIntro = () => import('../views/pageIn/statement/components/ProduceInfo.vue')
const ProductTeam = () => import('../views/pageIn/statement/components/ProductTeam.vue')
const ProductCulture = () => import('../views/pageIn/statement/components/ProductCulture.vue')
const FeedBack = () => import('../views/pageIn/statement/components/FeedBack.vue')
const Infro = () => import('../views/pageIn/statement/components/Infro.vue')

// 个人中心路由
const PassPhone = () => import("../views/pageIn/mine/components/MeMessage/PassPhone")
const TimeLine = () => import("../views/pageIn/mine/components/MeMessage/TimeLine")
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/aboutUs',
  },
  {
    path: '/index',
    name: '首页',
    component: Index,
    redirect: '/aboutUs',
    children: [
      {
        path: '/aboutUs',
        name: 'aboutUs',
        component: AboutUs
      },
      {
        path: '/competition',
        name: 'competition',
        component: Competition
      },
      {
        path: '/joinUs',
        name: 'joinUs',
        component: JionUs
      },
      {
        path: '/plan',
        name: 'plan',
        component: Plan
      },
      {
        path: '/story',
        name: 'story',
        component: Story
      },
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: Login
  },
  {
    path: '/page',
    redirect: '/page/card'
  },
  {
    path: '/page/home',
    name: 'home',
    component: Home,
    children: [
      {
        path: '/page/card',
        name: 'card',
        component: Card
      },
      {
        path: '/page/mine',
        name: 'mine',
        component: Mine
      },
      {
        path: '/page/book',
        name: 'Book',
        component: Book
      },
      {
        path: '/page/createBook',
        name: 'CreateBook',
        component: CreateBook
      },
      {
        path: '/page/plans',
        name: 'Plans',
        component: Plans
      },
      {
        path: '/page/time',
        name: 'Time',
        component: Time
      },
      {
        path: '/page/wirte/:lid/:docid',
        name: 'Wirte',
        component: Wirte,
        props: true
      },
      // 柚子打卡
      {
        path: '/page/createClock',
        name: 'createClock',
        redirect: '/page/createClock/publish',
        component: CreateClock,
        children: [
          {
            path: '/page/createClock/publish',
            name: 'publish',
            component: Publish
          },
          {
            path: '/page/createClock/publishDetail/:sid',
            name: 'publishDetail',
            component: PublishDetail,
            props: true
          },
          {
            path: '/page/createClock/createPublish',
            name: 'createPublish',
            component: CreatePublish
          },
          {
            path: '/page/createClock/createMessage',
            name: 'createMessage',
            component: CreateMessage
          },
        ]
      },
      {
        path: '/page/statement',
        name: 'statement',
        component: Statement
      },
      // 柚子小组
      {
        path: '/page/group',
        name: 'group',
        redirect: '/page/group/groupShow',
        component: Group,
        children:
        [
          {
            path: '/page/group/createGroup',
            name: 'CreateGroup',
            component: CreateGroup
          },
          {
            path: '/page/group/groupShow',
            name: 'GroupShow',
            component: GroupShow
          },
          {
            path: '/page/group/groupdetail/:listId',
            name: 'GroupDetail',
            component: GroupDetail,
            // 将动态路由参数映射到组件的props中，访问和性能都很好
            props: true
          },
          {
            path: '/page/group/writeArticle/:listId/:groId',
            name: 'writeArticle',
            component: writeArticle,
            props: true
          },
          {
            path: '/page/group/groupsetting/:listId',
            name: 'groupsetting',
            component: GroupSetting,
            props: true
          },
          {
            path: 'page/group/articleshow/:listId/:groId',
            name: 'ArticleShow',
            component: ArticleShow,
            props: true
          }
        ]
      },
      // 消息中心
      {
        path: '/page/message',
        name: 'message',
        component: Message,
        children: [
          {
            path: 'sign',
            name: 'sign',
            component: Sign
          },
          {
            path: 'notice',
            name: 'notice',
            component: Notice
          },
          {
            path: 'otherMessage',
            name: 'otherMessage',
            component: OtherMessage
          }
        ]
      },
      // 关于我们
      {
        path: '/page/statement',
        name: 'statement',
        component: StateMent,
        redirect: '/page/statement/productintro',
        children: [
          {
            path: 'productintro',
            name: 'productintro',
            component: ProductIntro
          },
          {
            path: 'productteam',
            name: 'productteam',
            component: ProductTeam
          },
          {
            path: 'productculture',
            name: 'productculture',
            component: ProductCulture
          },
          {
            path: 'feedback',
            name: 'feedback',
            component: FeedBack
          },
          {
            path: 'Infro',
            name: 'infro',
            component: Infro
          }
        ]
      },
      // 个人中心
      {
        path: '/page/mine',
        name: 'mine',
        redirect: '/page/mine/passphone',
        component: Mine,
        children: [
          {
            path: 'passphone',
            name: 'passphone',
            component: PassPhone
          },
          {
            path: 'timeline',
            name: 'timeline',
            component: TimeLine
          }
        ]
      }
    ]
  }
]

const router = new VueRouter({
  mode: 'history',
  routes
})
//  挂载路由导航守卫
router.beforeEach((to, from, next) => {
  const user = JSON.parse(window.sessionStorage.getItem('user'))
  if (to.path.startsWith('/page')) {
    if (user) {
      next()
    } else {
      next('/login')
    }
  } else {
    next()
  }
})
export default router
